//
//  MasterViewController.m
//  xingfugangwan
//
//  Created by rainday on 14/12/15.
//  Copyright (c) 2014年 rainday. All rights reserved.
//

#import "MasterViewController.h"
#import "QianyueTableViewController.h"
#import "PreBookViewController.h"
#import "InfoCenterViewController.h"
#import "NewPreViewController.h"

@interface MasterViewController ()

#define KEY @[@[@"首页",@"签约"],@[@"业务中心",@"通知"],@[@"预约"]]



@property (nonatomic ,readonly) NSDictionary *dictionary;


@end



@implementation MasterViewController

- (void)awakeFromNib {
    [super awakeFromNib];
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        self.clearsSelectionOnViewWillAppear = NO;
        self.preferredContentSize = CGSizeMake(320.0, 600.0);
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
//    NSArray *array = [self.splitViewController viewControllers];
//    UINavigationController *secondNav = (UINavigationController *)array[1];
//    UIViewController *detailViewController = (UIViewController *)secondNav.viewControllers[0];
//    UIBarButtonItem *leftButtonItem = detailViewController.navigationItem.leftBarButtonItem;
    
    QianyueTableViewController *qianyueViewController = [[QianyueTableViewController alloc] init] ;
    NewPreViewController *preBookVC = [[NewPreViewController alloc] initWithNibName:@"NewPreViewController" bundle:nil];
    InfoCenterViewController *infoCenterVC = [[InfoCenterViewController alloc] initWithNibName:@"InfoCenterViewController" bundle:nil];
    
    
    
    UINavigationController *qianyueNav = [[UINavigationController alloc] initWithRootViewController:qianyueViewController ];
    UINavigationController *preBookNav = [[UINavigationController alloc] initWithRootViewController:preBookVC];
    UINavigationController *infoCenterNav = [[UINavigationController alloc] initWithRootViewController:infoCenterVC];
    
    qianyueNav.navigationBar.barTintColor = [UIColor colorWithRed:71.0/255 green:102.0/255 blue:166.0/255 alpha:1.0];
    preBookNav.navigationBar.barTintColor = [UIColor colorWithRed:71.0/255 green:102.0/255 blue:166.0/255 alpha:1.0];
    infoCenterNav.navigationBar.barTintColor = [UIColor colorWithRed:71.0/255 green:102.0/255 blue:166.0/255 alpha:1.0];
    _dictionary = [NSDictionary dictionaryWithObjectsAndKeys:qianyueNav,@"签约",[self.splitViewController viewControllers][1],@"作品",preBookNav,@"预约",infoCenterNav,@"业务中心", nil];
    
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self.view setBackgroundColor:[UIColor colorWithRed:220.0/255 green:220.0/255 blue:220.0/255 alpha:1.0]];
   
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    
    
    
    
    
}



#pragma mark - Segues

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([[segue identifier] isEqualToString:@"showDetail"]) {
       
        
        
        if ([self.splitViewController respondsToSelector:@selector(displayModeButtonItem)]) {
            
        }else{
            
        }
        
       
       
    }
}

#pragma mark - Table View


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 30;
}


-
(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60.0;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [KEY[section] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];

    cell.backgroundColor = [UIColor colorWithRed:240.0/255 green:240.0/255 blue:240.0/255 alpha:1.0];
    cell.separatorInset = UIEdgeInsetsMake(2, 0, 0, 0);
    if (indexPath.section < [KEY count] && indexPath.row <[KEY[indexPath.section] count] ) {
         cell.textLabel.text = KEY[indexPath.section][indexPath.row];
    }
    [cell.imageView setImage:[UIImage imageNamed:cell.textLabel.text]];
    
   
    
    return cell;
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return NO;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSArray *array = [self.splitViewController viewControllers];
    if (indexPath.section<[KEY count] && indexPath.row<[KEY[indexPath.section] count] && [_dictionary objectForKey:KEY[indexPath.section][indexPath.row]]) {
        self.splitViewController.viewControllers = [NSArray arrayWithObjects:[array objectAtIndex:0],[_dictionary objectForKey:KEY[indexPath.section][indexPath.row]], nil];
    }
    
    
    return;
    
    
    
}

@end
